//
//  Elaborate_View.m
//  SecondPage
//
//  Created by winston on 13-4-10.
//  Copyright (c) 2013年 winston. All rights reserved.
//

#import "Elaborate_View.h"

@implementation Elaborate_View
@synthesize autoID,moduleKey;

- (id)initWithFrame:(CGRect)frame autoID:(NSString*)_autoID ModuleID:(NSString *)_moduleID
{
    self = [super initWithFrame:frame];
    if (self) {
        self.autoID = _autoID;
        self.moduleKey = _moduleID;
        
        btnCompany = [[CustomButton alloc] initWithFrame:CGRectMake(frame.size.width-105, 420, 105, 52)];
        [self addSubview:btnCompany];
        [btnCompany release];
        [btnCompany setBackGroundNormalImagePath:@"AllAuto_Appearance_Button_Unselect"];
        [btnCompany setBackGroundHighLightImagePath:@"AllAuto_Appearance_Button_Select"];
        [btnCompany setNormalTitleColor:[UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:1.0]];
        [btnCompany setHighLightTitleColor:[UIColor whiteColor]];
        btnCompany.titleLabel.text = @"原厂精品";
        btnCompany.groupID = 1;
        btnCompany.tag = 1;
        [btnCompany addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
        
        btnBrand = [[CustomButton alloc] initWithFrame:CGRectMake(frame.size.width-105, 470, 105, 52)];
        [self addSubview:btnBrand];
        [btnBrand release];
        [btnBrand setBackGroundNormalImagePath:@"AllAuto_Appearance_Button_Unselect"];
        [btnBrand setBackGroundHighLightImagePath:@"AllAuto_Appearance_Button_Select"];
        [btnBrand setNormalTitleColor:[UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:1.0]];
        [btnBrand setHighLightTitleColor:[UIColor whiteColor]];
        btnBrand.titleLabel.text = @"特约店精品";
        btnBrand.groupID = 1;
        btnBrand.tag = 2;
        [btnBrand addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
        
        btnCompany.isSelect = YES;
        btnBrand.isSelect = NO;
        [btnCompany sendActionsForControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

-(void)onClick:(CustomButton *)sender
{
    if (sender.tag == 1) {
        if (companyView == nil) {
            companyView = [[ElaborateView_Company alloc] initWithFrame:self.bounds autoID:self.autoID ModuleID:self.moduleKey];
        }
        
        [self insertSubview:companyView belowSubview:btnCompany];
        if (brandView) {
            [brandView removeFromSuperview];
        }
    }
    else
    {
        if (brandView == nil) {
            brandView = [[ElaborateView_Brand alloc] initWithFrame:self.bounds autoID:self.autoID ModuleID:self.moduleKey];
        }
        
        [self insertSubview:brandView belowSubview:btnCompany];
        if (companyView) {
            [companyView removeFromSuperview];
        }
    }
}


-(void)dealloc
{
    SafeRelease(brandView);
    SafeRelease(companyView);
    self.autoID = nil;
    self.moduleKey = nil;
    
    [super dealloc];
}

@end
